#include "Log.h"
#include "loghandler.h"
#include "jid.h"
#include "client.h"
#include "connectionlistener.h"
#include "Poco/Util/Application.h"
#include "iostream"
#include "Jingle.h"
#include "XMPPClient.h"
#include "MediaSession.h"
#include "IceLink.h"
#include "Poco/Net/NetworkInterface.h"
#include "IceLinkPool.h"


using namespace cm_base;
using namespace cm_xmpp;
using namespace cm_nat;
using Poco::Net::NetworkInterface;


//client
int main2()
{
    Poco::Util::Application* p_app = new Poco::Util::Application;
    p_app->loadConfiguration("c:/test/test_case.xml");



    XMPPClient client("cmjabber_b@jabber.org", "123456", "client", "jabber.org");
    client.setup();
    client.connect();

    JingleManager* p_jingleManager = client.getJingleManager();

    MediaSession* p_mediaSessioin = new MediaSession(MediaSession::generateSid());

    p_jingleManager->registerJingleSession(p_mediaSessioin);

    JID jid("cmjabber_b@jabber.org/daemon");
    
    IceLinkPool pool;
    SocketAddress stunSa("stunserver.org", 3478);
    pool.setHostIP( IPAddress("192.168.0.128") );
    pool.setup(3, stunSa );


    std::string input;
    while (std::cin>>input)
    {
        IceLink* p_link = pool.getLink();
        if( p_link ){
            p_mediaSessioin->initiate( jid );
            p_mediaSessioin->sendCandidate( p_link->getStunReflexAddress() );
        }

     
    }

    return 0;
}

//daemon
int main()
{
    Poco::Util::Application* p_app = new Poco::Util::Application;
    p_app->loadConfiguration("c:/test/test_case.xml");


    XMPPClient client("cmjabber_b@jabber.org", "123456", "daemon", "jabber.org");
    client.setup();
    client.connect();

    JingleManager* p_jingleManager = client.getJingleManager();

    JID jid("cmjabber_b@jabber.org/daemon");

    IceLinkPool pool;
    SocketAddress stunSa("stunserver.org", 3478);
    pool.setHostIP( IPAddress("192.168.0.128") );
    pool.setup(3, stunSa );


    std::string input;
    while (std::cin>>input)
    {
        IceLink* p_link = pool.getLink();
        if( p_link ){
            //p_mediaSessioin->initiate( jid );
            //p_mediaSessioin->sendCandidate( p_link->getStunReflexAddress() );
        }


    }

    return 0;
}

